﻿@model IEnumerable<IGrouping<string, HQPad.Models.SkillItem>>

<h2>Skills</h2>

<table class="skills-table">
    <thead>
        <tr>
            <th>Skill</th>
            <th>Cost</th>
            <th class="ranks">Ranks <span class="small">(of max)</span></th>
            <th class="points">Points</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var group in Model)
        {
            <tr class="skill-group" group="@Html.Raw(group.Key.Replace(" ","-"))">
                <td colspan="4">@Html.Raw(group.Key)</td>
            </tr>
            foreach (var skill in group) {
                <tr group="@Html.Raw(group.Key.Replace(" ","-"))" skillid="@Html.Raw(skill.Slug)" @Html.Raw(skill.Allowed ? "" : "class=\"not-allowed\"")>
                    <td class="name">
                        <span @(skill.Ranks == 0 ? "" : "class=bought")>@Html.Raw(skill.Name)</span>
                        <ul class="inline-list">
                            @if (skill.StatusSkill) {
                                <li class="status-skill tooltipable">S</li>
                                <div class="tooltip">A status skill</div>
                            }                        
                            <li class="description tooltipable">Description</li>
                            <div class="tooltip">Description:<br />@Html.Raw(skill.Description)</div>
                        </ul>
                    </td>
                    <td>@Html.Raw(skill.CostDescription)</td>
                    <td class="ranks">
                        @if (skill.Allowed) {
                            <span @(skill.Ranks == 0 ? "" : "class=bought")>
                                @if (!skill.MaxRanks.HasValue || (skill.MaxRanks.HasValue && skill.MaxRanks.Value > 1))
                                { 
                                    <span class="editable" skillid="@Html.Raw(skill.Slug)" maxranks="@Html.Raw(skill.MaxRanks.HasValue ? skill.MaxRanks.Value.ToString() : "1000")">@Html.Raw(skill.Ranks.ToString())</span>
                                }
                                else
                                {
                                    <input type="checkbox" skillid="@Html.Raw(skill.Slug)" class="one-rank-skill" @Html.Raw((skill.Ranks > 0) ? "checked=\"checked\"" : "") />
                                }
                            </span> 
                            if (!skill.MaxRanks.HasValue || (skill.MaxRanks.HasValue && skill.MaxRanks.Value > 1))
                            { 
                                <span>
                                    (<span class="ranks-maximum">of @Html.Raw(skill.MaxRanks.HasValue ? skill.MaxRanks.Value.ToString() : "&#8734;")</span>)
                                </span>
                            }
                        }
                    </td>
                    <td class="points"><span @(skill.Ranks == 0 ? "" : "class=bought")>@Html.Raw(skill.Cost.ToString())</span></td>
                </tr>
            }
        }
    </tbody>
</table>